export const getdate = () => {
    // 格式化日对象
    let date = new Date();
    let year = date.getFullYear() // 年
    let month = date.getMonth() + 1; // 月
    let month2 = month + 1 > 13 ? 1 : month + 1
    month2 = month2 <= 9 ? "0" + month2 : month2
    // 给一位数的数据前面加 “0”
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    let date1 = year + "-" + month
    let date2 = year + "-" + month2
    return [date1,date2]

}
export const formatStringDate=(date)=>{
    // let tmp = date.substr(6, date.length-8);
    let data = new Date(date);
    let year = data.getFullYear();
    let month = data.getMonth() + 1;
    let day = data.getDate();
    let hour = data.getHours()<10?'0'+data.getHours():data.getHours();
    let minute = data.getMinutes()<10?'0'+data.getMinutes():data.getMinutes();
    let second = data.getSeconds()<10?'0'+data.getSeconds():data.getSeconds();11
    return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
}
export const getNowDate = (i) => {
    var date = new Date();
    var sign2 = ":";
    var year = date.getFullYear() // 年
    var month = date.getMonth() + 1; // 月
    // 给一位数的数据前面加 “0”
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    return year + "-" + month + "-" + i + " " + '00' + sign2 + '00' + sign2 + '00';
}
//比较两个时间  time1，time2均为日期类型
//判断两个时间段是否相差 m 个月
export const completeDate=(time1, time2, m)=> {
    var diffyear = time2.getFullYear() - time1.getFullYear();
    var diffmonth = diffyear * 12 + time2.getMonth() - time1.getMonth();
    if (diffmonth < 0) {
        return false;
    }
    var diffDay = time2.getDate() - time1.getDate();
    if (diffmonth < m || (diffmonth == m && diffDay <= 0)) {
        if (diffmonth == m && diffDay == 0) {
            var timeA = time1.getHours() * 3600 + 60 * time1.getMinutes() + time1.getSeconds();
            var timeB = time2.getHours() * 3600 + 60 * time2.getMinutes() + time2.getSeconds();
            if (timeB - timeA > 0) {
                return false;
            }
        }
        return true;
    }
    return false;
}
export function  getLastMonthDate(dateString){ // 将指定格式的日期字符串转换为 Date 对象
    var date = new Date(dateString);
    // 获取当前月份
    var currentMonth = date.getMonth();
    // 将月份减1
    date.setMonth(currentMonth - 1);
    // 格式化日期
    var formattedDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
    return formattedDate;
}
export function getLastDayOfMonth(timeParam) {
    const timeObj = new Date(timeParam)
    const fullYear = timeObj.getFullYear()
    const nextMounth = timeObj.getMonth() + 1
    console.log(fullYear, nextMounth)
    const LastDaysTimeStamp = new Date(fullYear, nextMounth, 0, 0, 0, 0).getTime() - 1
    console.log('LastDaysTimeStamp', LastDaysTimeStamp)
    return LastDaysTimeStamp
}
/**
 * 获取某月的周列表，每月有周一的才能参与计算周
 * @param {*} year
 * @param {*} month
 */
export function getMounthOfWeekList(year, month) {
    if (!year || !month) {
        return []
    }
    let zhou = ''
    let weekList = []
    let numChinese = { 1: '一', 2: '二', 3: '三', 4: '四', 5: '五' }
    let time = year + `/` + month + `/` + `01`
    let startDate = new Date(time)
    let day = parseInt(startDate.getDay()) == 0 ? 7 : parseInt(startDate.getDay())
    // 判断当月有几周
    let days = new Date(year, month, 0).getDate()
    let y = days % 7
    if (7 - day >= y) {
        zhou = parseInt(days / 7) + 1
    } else {
        zhou = parseInt(days / 7) + 2
    }
    let endDate = new Date(year + `/` + month + `/` + days).getDay()
    if (endDate == 0) {
        zhou = zhou - 1
    }
    // 自定义逻辑，每月有周一的才能参与计算周
    if (day !== 1) {
        zhou = zhou - 1
    }
    console.log(month + '月有含周一的周数为：' + zhou + '周')
    for (let i = 1; i <= zhou; i++) {
        let weekStartDate = new Date(year, month - 1, 9 - day + 7 * (i - 1)).format('yyyy-MM-dd')
        let weekEndDate = new Date(year, month - 1, 8 - day + 7 * i).format('yyyy-MM-dd')
        weekList.push({
            label: `第${numChinese[i]}周`,
            value: i,
            weekStartDate,
            weekEndDate,
            year,
            month,
            week: i
        })
    }
    console.log('weekList', weekList)
    return weekList
}